"use strict";
var _core = require("@pricking/core");
var _indexController = _interopRequireDefault(require("../base/IndexController"));
var _novelParser = _interopRequireDefault(require("../../services/novel-parser"));
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
    var desc = {};
    Object.keys(descriptor).forEach(function(key) {
        desc[key] = descriptor[key];
    });
    desc.enumerable = !!desc.enumerable;
    desc.configurable = !!desc.configurable;
    if ("value" in desc || desc.initializer) {
        desc.writable = true;
    }
    desc = decorators.slice().reverse().reduce(function(desc, decorator) {
        return decorator ? decorator(target, property, desc) || desc : desc;
    }, desc);
    if (context && desc.initializer !== void 0) {
        desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
        desc.initializer = undefined;
    }
    var own = Object.getOwnPropertyDescriptor(target, property);
    if (own && (own.get || own.set)) {
        delete desc.writable;
        delete desc.initializer;
    }
    if (desc.initializer === void 0) {
        Object.defineProperty(target, property, desc);
        desc = null;
    }
    return desc;
}
function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
var _class, _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _dec19;
var _dec20 = (0, _core).Controller('/v3/analyze');
let AnalyzeController = _class = _dec20(((_class = class AnalyzeController extends _indexController.default {
    async getChapter() {
        const { query: { url  } ,  } = this.ctx;
        this.validator.required(url).supportedUrl(url);
        const result = await this.novelService.analyzeChapter(url);
        this.ctx.success(result);
    }
    async getCatalog() {
        const { query: { url  } ,  } = this.ctx;
        this.validator.required(url).supportedUrl(url);
        const result = await this.novelService.analyzeList(url);
        this.ctx.success(result);
    }
    async getLatestChapter() {
        const { query: { url  } ,  } = this.ctx;
        /** 通常最新章节的 url 与书籍目录 url 相同，当然也有不同的 */ this.validator.required(url).supportedUrl(url);
        const result = await this.novelService.analyzeLatestChapter(url);
        this.ctx.success(result);
    }
    async getLatestChapters() {
        const { body: list  } = this.ctx.request;
        this.validator.isNumber(list.length, '不符合规则的参数').required(list[0].url, '不符合规则的参数 - url');
        const result = await this.novelService.analyzeLatestChapters(list);
        this.ctx.success(result);
    }
    async getOrigin() {
        const { body: list  } = this.ctx.request;
        const result = await this.novelService.getOrigin(list);
        this.ctx.success(result);
    }
    constructor(...args){
        super(...args);
        this.novelService = new _novelParser.default();
    }
}) || _class, _dec = (0, _core).Get('/chapter'), _dec1 = (0, _core).Description('解析章节'), _dec2 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec3 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", []), _applyDecoratedDescriptor(_class.prototype, "getChapter", [
    _dec,
    _dec1,
    _dec2,
    _dec3
], Object.getOwnPropertyDescriptor(_class.prototype, "getChapter"), _class.prototype), _dec4 = (0, _core).Get('/catalog'), _dec5 = (0, _core).Description('获取书籍目录'), _dec6 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec7 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", []), _applyDecoratedDescriptor(_class.prototype, "getCatalog", [
    _dec4,
    _dec5,
    _dec6,
    _dec7
], Object.getOwnPropertyDescriptor(_class.prototype, "getCatalog"), _class.prototype), _dec8 = (0, _core).Get('/latest-chapter'), _dec9 = (0, _core).Description('获取最新章节'), _dec10 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec11 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", []), _applyDecoratedDescriptor(_class.prototype, "getLatestChapter", [
    _dec8,
    _dec9,
    _dec10,
    _dec11
], Object.getOwnPropertyDescriptor(_class.prototype, "getLatestChapter"), _class.prototype), _dec12 = (0, _core).Post('/batch-latest-chapters'), _dec13 = (0, _core).Description('批量获取最新章节'), _dec14 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec15 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", []), _applyDecoratedDescriptor(_class.prototype, "getLatestChapters", [
    _dec12,
    _dec13,
    _dec14,
    _dec15
], Object.getOwnPropertyDescriptor(_class.prototype, "getLatestChapters"), _class.prototype), _dec16 = (0, _core).Post('/origin'), _dec17 = (0, _core).Description('获取书源最新章节'), _dec18 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec19 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", []), _applyDecoratedDescriptor(_class.prototype, "getOrigin", [
    _dec16,
    _dec17,
    _dec18,
    _dec19
], Object.getOwnPropertyDescriptor(_class.prototype, "getOrigin"), _class.prototype), _class)) || _class;
module.exports = AnalyzeController;
